<?php

namespace App\Http\Controllers\Api;

use App\Exports\PandianExport;
use App\Http\Controllers\Controller;
use App\Rep\CheckLogRep;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;

class CheckLog extends Controller
{
    //盘点列表
    protected $rep;

    public function __construct(Request $request)
    {
        $this->rep = new CheckLogRep();
    }

    /**
     * 获取盘点列表
     * @param Request $request
     */
    public function getCheckLogList(Request $request){
        $params = $request->all();
        $export = $request->get('export')??0;
        if($export == 1){
            try{
                $params['order_name'] = '盘点列表';
                $filename = date('ymdhis').'.xlsx';
                $export = new PandianExport($params);
                return Excel::download($export,$filename,\Maatwebsite\Excel\Excel::XLSX,[
                    'Content-Type'=> 'application/octet-stream',
                    'Content-Disposition'=> 'attachment; filename='.$filename,
                    'Content-Transfer-Encoding'=> 'binary',
                ]);
            }catch(\Exception $exception){
                return re(0,[],$exception->getMessage());
            }
        }
        $data = $this->rep->getCheckLogListRep($params);
        return re(0,$data,'success');
    }

    /**
     * 批量设置已发货
     */
    public function batchSettingYifahuo(Request $request){
        $params = $request->all();
        $data = $this->rep->batchSettingYifahuoRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }



}
